	$(document).ready(function(){
		placeholders("#role_name");
		$("#tbGrid").flexigrid( {
			url :  appCtx + "system/role/loadAllRoles.html",
			dataType : 'json',
			colModel : [{
				display : '角色名称',
				name : 'role_name',
				width : 120,
				sortable:true,
				align : 'left'
			},{
				display : '是否生效',
				name : 'enable',
				width : 120,
				sortable:true,
				align : 'left',
				handlefunction : 'getEnable',
				paramcolnames : ['enable']
			},{
				display : '描述',
				name : 'memo',
				width : 250,
				sortable:true,
				align : 'left'
			}],
			resizable: false,
			sortname : "id",
			sortorder : "desc",
			usepager : true,
			showToggleBtn: false, 
			showTableToggleBtn : true,
			useRp : true,
			rp : 10,
			checkbox : true,
			rowId : 'id',
			singleSelect:false,
			height : nav.whiceH[1] - 78,
		});			
	});
	
	function getEnable(enable){
		if(enable == "true"){
			return "是";
		}else{
			return "否";
		}
	}
	
	function query(){
		var role_name = $("#role_name").val();
		//查询参数
		var params = [{name : 'role_name',value : role_name}];
		
		$("#tbGrid").flexOptions({
			newp : 1,
			params : params
		}).flexReload();
	}

	function addButton(){
		var url = appCtx + "system/role/init.html";
		window.parent.doDataDialog("insert","增加角色",this.name,"saveRole()", "query()",url);
	}
	
	 function update(){
		var checkedIds = $("#tbGrid").getCheckedRows();
		if(checkedIds.length<1){
			window.parent.doAlert('请选择要修改的数据！');
			return;
		}
		if(checkedIds.length > 1){
			window.parent.doAlert('只能修改一条数据！');
			return;
		}
		var url = appCtx + "system/role/loadRoleById.html?roleId="+checkedIds[0].replace(/row/, "");
		window.parent.doDataDialog("update","修改角色",this.name,"saveRole()", "query()",url);
	}	 
	 
	 
	function deleteData(){
		var checkedIds = $("#tbGrid").getCheckedRows();		
		if(checkedIds.length<1){
			window.parent.showVelidateModal('请选择要删除的数据！');
			return;
		}
		window.parent.doConfirm("确定要删除吗？删除后将无法恢复！",this.name,"deleteConfirm()");
    }

    function deleteConfirm(){
    	var checkedIds = $("#tbGrid").getCheckedRows();
	    $.ajax({
	        type: 'post',
	        async: false,
	        url: appCtx + "system/role/deleteRole.html",
			data:{ids:checkedIds.toString()},
	        cache: false,
	        dataType : "JSON",
	        success: function (data) {
	        	if(data.code == "0"){
					$("#tbGrid").flexReload();
					global.ajaxLoading.pop('操作成功!',false,2000);
				}else{
					showVelidateModal("操作失败!");
				}
	        }
	    });		     
	 }
